package ten;

public class UnsafeTest01 {
    public static void main(String[] args) {
        Runnable r = new UnsafeWeb12306();
        new Thread(r, "ct1").start();
        new Thread(r, "ct2").start();
        new Thread(r, "ct3").start();
    }
}

class UnsafeWeb12306 implements Runnable{

    private boolean flag = true;
    private int ticketNums = 1000;

    @Override
    public void run() {
        while (flag){
            test();
        }
    }

    private void test() {
        if(ticketNums <= 0){
            flag = false;
            return;
        }
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"--->"+ ticketNums--);
    }
}
